﻿var Common = {};
Common.ExtendObject = function(source, target) {
    try {
        if (target == source) {
            return;
        }
        else {
            for (var prop in source) {
                if ((typeof (source[prop]) != "object") || (source[prop] instanceof Array)) {
                    // Do not ask for if the Array's items are objects because it is not correct extend data. Only structures.
                    if(target[prop] == undefined)
                        target[prop] = source[prop];
                }
                else {
                    if(target[prop] == undefined)
                    {
                        target[prop] = {};
                        Common.ExtendObject(source[prop], target[prop]);
                    }
                }
            }
        }
    }
    catch (Error) { Common.ShowError(Error); }
};
Common.GetLastBaseProperty = function GetLastBaseProperty(obj) {
    try {
        if(!obj.Base)
        {
            obj.Base = {};
            return obj.Base;
        }
        else
        {
            return arguments.callee(obj.Base);
        }
    }
    catch(Error) { ShowError(Error); }
};
Common.ShowError = function(error) {
    try {
        var errorMSG = ((error.message != undefined) && (error.message != null))
                            ? error.message
                            : error;

//        if(Global.IsTesting)
            alert(errorMSG);
//        else
//            window.status = errorMSG;
    }
    catch (Error) { window.status = Error.Message; }
};
var GetLastBaseProperty = function GetLastBaseProperty(obj) {
    try {
        if(!obj.Base)
        {
            obj.Base = {};
            return obj.Base;
        }
        else
        {
            return arguments.callee(obj.Base);
        }
    }
    catch(Error) { ShowError(Error); }
};